package com.qf.smsplatform.search.mq;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.search.service.SearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * projectName: sms-platform
 *
 * @author: 黄睿武
 * time: 2021/8/23 16:28
 * description: 监听写日志队列的消息
 */

@Component
public class SendLogListener {

    @Autowired
    private SearchService searchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {
        //1.调用service保存submit到es中
        searchService.index(submit);

        //2手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }



}
